package com.tonny.bootdemo.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import com.tonny.bootdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href=mailto:yikaitang@meituan.com>伊开堂</a>
 * @date 2018/2/6 20:25
 */
@RestController
public class IndexController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public Object index() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("appName", "boot-demo");
        Date now = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        map.put("now", now.getTime());
        map.put("time", format.format(now));
        return map;
    }

    @RequestMapping("/login/{id}")
    public Object login(@PathVariable Long id) {
        return userService.findUser(id);
    }

}
